package com.ziyun.pop.rest.module.order;

import com.service.order.model.order.OrderMessageParamDto;
import com.service.order.model.order.OrderMessageVO;
import com.ziyun.pop.common.utils.UserUtils;
import com.ziyun.pop.modules.order.dto.TwbOrderDetailDto;
import com.ziyun.pop.modules.order.dto.TwbOrderListDto;
import com.ziyun.pop.modules.order.dto.TwbOrderParamDto;
import com.ziyun.pop.modules.order.service.ErpOrderService;
import io.renren.common.utils.R;
import io.renren.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "OrderRestApi", tags = "订单列表")
@RestController
@RequestMapping("popApi/order/")
public class OrderRestApi {

    @Autowired
    private ErpOrderService erpOrderService;

	@ApiOperation(value = "订单列表")
    @ApiResponses(value = @ApiResponse(code =200, message = "查询订单列表成功",response =TwbOrderListDto.class))
	@PostMapping("/orderListApi")
    public R list(@RequestBody TwbOrderParamDto twbOrderParamDto){
        twbOrderParamDto.setSellerId(UserUtils.getCurentUser().getSellerId());
        return erpOrderService.queryPageForTwbOrderList(twbOrderParamDto);
    }

    @ApiOperation(value = "获取订单详细信息", notes = "根据orderNo查询订单信息")
    @ApiResponses(value = @ApiResponse(code = 200, message = "获取订单信息成功",response =TwbOrderDetailDto.class))
    @ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String", paramType = "path",example= "519010309141692")
    @RequestMapping(value="/getOrderInfo/{orderNo}", method= RequestMethod.GET)
    public R getOrderInfo(@PathVariable String orderNo){
        return erpOrderService.getTwbOrderInfo(orderNo);
    }

    @ApiOperation(value = "根据订单号审核订单", notes = "")
    @ApiResponses(value = @ApiResponse(code = 200, message = "审核成功"))
    @ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String", paramType = "query",example= "190103084844490")
    @GetMapping("/audit")
    public R audit(@RequestParam("orderNo") String orderNo){
        SysUserEntity curentUser = UserUtils.getCurentUser();
        return erpOrderService.audit(orderNo,curentUser);
    }

    @ApiOperation(value = "根据订单号进行生产完成操作", notes = "")
    @ApiResponses(value = @ApiResponse(code = 200, message = "生产完成成功"))
    @ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String", paramType = "query",example= "190103084844490")
    @GetMapping("/productFinish")
    public R productFinish(@RequestParam("orderNo") String orderNo){
        SysUserEntity curentUser = UserUtils.getCurentUser();
        return erpOrderService.productFinish(orderNo,curentUser);
    }

    @ApiOperation(value = "获取订单消息", notes = "")
    @ApiResponses(value = @ApiResponse(code = 200, message = "获取成功", response = OrderMessageVO.class))
    @PostMapping("/getOrderMessage")
    public R getOrderMessage(@RequestBody OrderMessageParamDto orderMessageParamDto){
        SysUserEntity curentUser = UserUtils.getCurentUser();
        Long sellerId = curentUser.getSellerId();
        Long mallUserId = curentUser.getMallUserId();
        orderMessageParamDto.setSellerId(sellerId);
        return erpOrderService.getOrderMessage(orderMessageParamDto, mallUserId);
    }

}
